<template>
  <el-card class="reply-item">
    <div class="user-info">
      <router-link
        :to="{ name: `info-center`, params: { userId: reply.author } }"
      >
        <avatar :user="reply" size="large"></avatar>
      </router-link>
      <div class="text">
        <router-link
          :to="{ name: `info-center`, params: { userId: reply.author } }"
        >
          <div class="nickname">{{ reply.nickname }}</div>
        </router-link>
        <div class="reply-time">{{ reply.createAt | myTime }}</div>
      </div>
    </div>
    <router-link
      :to="{
        name: `post`,
        params: { postId: reply.post },
        query: {
          cid: reply.parentComment ? reply.parentComment : reply.commentId
          ,refCid:reply.commentId
        },
      }"
    >
      <div class="reply-content">{{ reply.content }}</div>
    </router-link>
    <router-link :to="{ name: `post`, params: { postId: reply.post } }">
      <div class="title">{{ reply.postTitle }}</div>
    </router-link>
    <div class="footer">
      <router-link :to="{ name: `forum`, params: { id: reply.forumId } }">
        <div class="from">{{ reply.forumName }}</div>
      </router-link>
      <div class="reply" @click="clickReplyAction(reply.commentId)">
        <i class="el-icon-chat-dot-square" style="margin-right: 5px"></i>
        {{ commentInputCid == reply.commentId ? "收起回复" : "回复" }}
      </div>
    </div>
    <div class="input-wrapper" v-if="commentInputCid == reply.commentId">
      <comment-input
        :comment="{
          post: reply.post,
          forum: reply.forumId,
          type: 1,
          parentComment: reply.commentId,
          replyToSub: reply.replyToSub,
        }"
      ></comment-input>
    </div>
  </el-card>
</template>

<script>
import CommentInput from "@/components/postItems/CommentInput.vue";
export default {
  props: ["reply"],
  components: {
    CommentInput,
  },
  methods: {
    clickReplyAction(cid) {
      if (cid == this.commentInputCid) this.changeCommentInput(0);
      else this.changeCommentInput(cid);
    },
  },
};
</script>

<style lang="less" scoped>
@import "@/assets/less/common.less";
.title,
.reply-content {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reply-item {
  width: 550px;
  margin: 0 auto;
  margin-bottom: 20px;
}
.reply-item:last-child {
  margin-bottom: 0;
}
.user-info {
  display: flex;
  .el-avatar {
    margin-right: 20px;
    height: 48px;
    width: 48px;
  }
  .text {
    font-size: 14px;
    line-height: 24px;
  }
}
.reply-content {
  margin-top: 20px;
}
.title {
  background: #f5f7fa;
  color: @regularText;
  padding: 10px;
  margin-top: 20px;
  border-radius: 5px;
}
.footer {
  font-size: 14px;
  margin-top: 20px;
  display: flex;
  justify-content: space-between;
  .reply {
    cursor: pointer;
  }
}
</style>